package com.ys.peony.ui.adapter;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ys.peony.R;
import com.ys.peony.app.BaseApplication;
import com.ys.peony.enums.BusinessDetailStatus;
import com.ys.peony.model.AppointModel;
import com.ys.peony.model.JiekuanrenModel;
import com.ys.peony.ui.activity.AddClientInfoActivity;
import com.ys.peony.ui.activity.AppointListActivity;
import com.ys.peony.ui.activity.BusiInfoActivity;
import com.ys.peony.ui.activity.DywListActivity;
import com.ys.peony.ui.activity.JiekuanrenListActivity;
import com.ys.peony.ui.view.zlistview.adapter.BaseSwipeAdapter;
import com.ys.peony.ui.view.zlistview.enums.DragEdge;
import com.ys.peony.ui.view.zlistview.enums.ShowMode;
import com.ys.peony.ui.view.zlistview.listener.SimpleSwipeListener;
import com.ys.peony.ui.view.zlistview.widget.ZSwipeItem;
import com.ys.peony.utils.LogUtil;

import java.util.List;

public class AppointListAdapter extends BaseSwipeAdapter {
    protected static final String TAG = AppointListAdapter.class.getSimpleName();
    private AppointListActivity context;
    private List<AppointModel> data;

    public AppointListAdapter(AppointListActivity context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public AppointModel getItem(int position) {
        return data == null ? null : data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getSwipeLayoutResourceId(int position) {
        return R.id.swipe_item;
    }

    @Override
    public View generateView(int position, ViewGroup parent) {
        return context.getLayoutInflater().inflate(R.layout.appoint_item_layout,
                parent, false);
    }

    @Override
    public void fillValues(final int position, final View convertView) {
        final ZSwipeItem swipeItem = convertView
                .findViewById(R.id.swipe_item);
        LinearLayout rightLL = convertView.findViewById(R.id.right_ll);
        TextView delBtn = convertView.findViewById(R.id.item_delete_tv);
        TextView nameTV = convertView.findViewById(R.id.yuyue_name_tv);
        TextView phoneTV = convertView.findViewById(R.id.yuyue_phone_tv);
        TextView carBranchTV = convertView.findViewById(R.id.yuyue_car_style_tv);
        TextView carNumTV = convertView.findViewById(R.id.yuyue_carnum_tv);
        TextView idCardTV = convertView.findViewById(R.id.yuyue_identification_tv);

        final AppointModel item = data.get(position);
        if (item == null) {
            return;
        }
        nameTV.setText(BaseApplication.getInstance().getResources().getString(R.string.name_lable) + item.getName());
        phoneTV.setText(BaseApplication.getInstance().getResources().getString(R.string.phone_lable) + item.getPhone());
        carBranchTV.setText(BaseApplication.getInstance().getResources().getString(R.string.jiekuanren_car) + item.getBrand_name());
        carNumTV.setText(BaseApplication.getInstance().getResources().getString(R.string.jiekuanren_carnum) + item.getPlate_number());
        idCardTV.setText(BaseApplication.getInstance().getResources().getString(R.string.identification_lable) + item.getId_card());

        swipeItem.setShowMode(ShowMode.PullOut);
        swipeItem.setDragEdge(DragEdge.Right);

        swipeItem.addSwipeListener(new SimpleSwipeListener() {
            @Override
            public void onOpen(ZSwipeItem layout) {
//                LogUtil.i(TAG, "打开:" + position);
            }

            @Override
            public void onClose(ZSwipeItem layout) {
//                LogUtil.i(TAG, "关闭:" + position);
            }

            @Override
            public void onStartOpen(ZSwipeItem layout) {
//                LogUtil.i(TAG, "准备打开:" + position);
            }

            @Override
            public void onStartClose(ZSwipeItem layout) {
//                LogUtil.i(TAG, "准备关闭:" + position);
            }

            @Override
            public void onHandRelease(ZSwipeItem layout, float xvel, float yvel) {
//                LogUtil.i(TAG, "手势释放");
            }

            @Override
            public void onUpdate(ZSwipeItem layout, int leftOffset,
                                 int topOffset) {
//                LogUtil.i(TAG, "位置更新");
            }
        });
        delBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                //context.delAppointItem(item.getId());
                swipeItem.close();
            }
        });

    }

    public void setData(List<AppointModel> date) {
        this.data = date;
        notifyDataSetChanged();
    }


}
